type A<T, U> = T|U

//泛型默认值
type A1<T=string> = T
let a:A1 = '123'
let b:A1<number> = 123
let c:A1<boolean> = true

type MyArray<T> = T[]
let d:MyArray<number> = [1,2,3]
let e:number[] = [1,2,3]

//函数
function foo<T>(n:T){

}

foo('123')
foo(123)

//函数与接口
interface B<T>{
    (n?:T):void
    default?:T
}
let f1: B<string> = (n) =>{}
let f2: B<number> = (n) =>{}

f1('hello')
f1.default='hi'

f2(123)
f2.default=456

class F1<T>{
    //告诉tsusername必须有值
    username!:T
}
class Baz extends F1<string>{}
let f = new F1<string>();
f.username = '123';

let f1 = new Baz();
f.username = '54'

//参数必须要有length属性，如string、
type C = {
    length:number
}
function foo1<T extends C>(n:T){
    return n.length
}

foo1('123')
//   foo1(123)


